#include <REGX52.H>
#include "uart.c"
#include "timer.c"
/**
 * 初始状态：LED熄灭。
 * 按下按键时，LED立即点亮。释放按键后，LED持续亮5秒后自动熄灭。
 * 如果LED没有熄灭时，按键按下，重置5秒时间
 */

unsigned int counter = 0;

sbit LED = P2 ^ 0;
sbit BTN = P2 ^ 6;

void timer0_ISR() interrupt 1
{
    // 每50ms中断一次
    TH0 = 0x4B;
    TL0 = 0xFD;

    if(BTN == 0)
    {
        LED = 1;
        counter = 0;
    }
    else {
        counter++;
    }
    
    if(counter >= 100)
    {
        LED = 0;
        counter = 0;
    }
}

void main()
{
    uart_init();
    timer0_init();
    timer0_isr_on();
    LED = 0;
    while(1)
    {
    }
}